﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

namespace GPSTrackingAdminWebsiteManager.Espanol.Pages
{
    public partial class AdminRoleManager : Telerik.Web.UI.RadAjaxPage
    {
        private GPSTrackingServerDB.Entities.AdminRoles Invoke_AdminRole(Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            Hashtable entity = new Hashtable();
            item.ExtractValues(entity);

            GPSTrackingServerDB.Entities.AdminRoles adminRolesEntity = new GPSTrackingServerDB.Entities.AdminRoles();
            adminRolesEntity.Description = entity[GPSTrackingServerDB.Entities.AdminRolesColumn.Description.ToString()].ToString();
            adminRolesEntity.IsActive = Convert.ToBoolean(entity[GPSTrackingServerDB.Entities.AdminRolesColumn.IsActive.ToString()]);

            return adminRolesEntity;
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void AdminRoleGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            AdminRoleGrid.DataSource = GPSTrackingServerDB.Data.DataRepository.AdminRolesProvider.GetAll();
        }

        protected void AdminRoleGrid_InsertCommand(object sender, GridCommandEventArgs e)
        {
            GPSTrackingServerDB.Entities.AdminRoles adminRolesEntity = Invoke_AdminRole(e);

            GPSTrackingServerDB.Data.DataRepository.AdminRolesProvider.Insert(adminRolesEntity);
        }

        protected void AdminRoleGrid_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            GPSTrackingServerDB.Entities.AdminRoles adminRolesEntity = Invoke_AdminRole(e);

            GridEditableItem editedItem = e.Item as GridEditableItem;

            adminRolesEntity.AdminRoleId = Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["AdminRoleId"]);

            GPSTrackingServerDB.Data.DataRepository.AdminRolesProvider.Update(adminRolesEntity);
        }

        protected void AdminRoleGrid_DeleteCommand(object sender, GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            GPSTrackingServerDB.Data.DataRepository.AdminRolesProvider.Delete(Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["AdminRoleId"]));
        }
    }
}